package com.whfc.cncit.helmet.codec;

import com.whfc.cncit.constant.CncitConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Description:
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/10/25 15:58
 */
public class CncitMsgCodecFactory {

    private static Logger logger = LoggerFactory.getLogger(CncitMsgCodecFactory.class);

    private static CncitUpMsgCodecR codecUpR = new CncitUpMsgCodecR();

    private static CncitUpMsgCodecS codecUpS = new CncitUpMsgCodecS();

    private static CncitDwMsgCodecRA codecDwRA = new CncitDwMsgCodecRA();

    private static CncitDwMsgCodecPS codecDwPS = new CncitDwMsgCodecPS();

    private static CncitUpMsgCodecPSA codecUpPSA = new CncitUpMsgCodecPSA();

    public static CncitMsgCodec create(String cmd) {

        CncitMsgCodec codec = null;
        switch (cmd) {
            case CncitConst.UP_CMD_R:
                codec = codecUpR;
                break;
            case CncitConst.UP_CMD_S:
                codec = codecUpS;
                break;
            case CncitConst.UP_CMD_H:
                codec = codecUpS;
                break;
            case CncitConst.DW_CMD_RA:
                codec = codecDwRA;
                break;
            case CncitConst.DW_CMD_PS:
                codec = codecDwPS;
                break;
            case CncitConst.UP_CMD_PSA:
                codec = codecUpPSA;
                break;
            default:
                logger.error("不能识别的命令:{}", cmd);
                break;
        }
        return codec;
    }
}
